﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ChessOnline
{
    public class PasswordManager
    {
        private string password;

        private string password_displayed; // mask all characters but last as * symbol

        public void SymbolAdded(char symbol)
        {
            password += symbol;
            password_displayed.Insert(password_displayed.Length - 1, "*");
            password_displayed += symbol;
        }

        public void SymbolDeleted()
        {
            password.Remove(password.Length - 1);
            password_displayed.Remove(password_displayed.Length - 1);
            password_displayed.Insert(password_displayed.Length - 1, password.Substring(password.Length - 1));
        }

        public string GetMaskedPassword(char symbol)
        {
            return password_displayed.Replace('*', symbol);
        }

        public string GetMaskedPassword()
        {
            return password_displayed;
        }

        public int GetPasswordLength()
        {
            return password.Length;
        }

        public void SetPassword(string pswd)
        {
            password = pswd;
            password_displayed = password;
            for (int i = 0; i < password_displayed.Length - 1; i += 1)
            {
                password_displayed.Insert(i, "*"); // "hello" -> "****o"
            }
        }

        public string GetPassword()
        {
            return password;
        }

        public void ClearPassword()
        {
            password = "";
        }
    }
}
